package com.example.padlock.view.sendvedio;

import java.io.IOException;
import java.io.OutputStream;

import android.hardware.Camera;
import android.util.Log;
import android.view.SurfaceHolder;

public class SendVedioTask extends Thread implements SurfaceHolder.Callback{

	private OutputStream mOS;
	private Camera camera;
	private int screenWidth = 640;
	private int screenHeight = 480;
	private SurfaceHolder holder;

	public SendVedioTask(OutputStream os) {
		this.mOS = os;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		super.run();
	}
	
	public void send(){
		
	}

	/**
	 * 初始化相机
	 * */
	private void cameraInit() throws IOException {
		Log.e("sendVedio", "start cameraInit");
		camera = Camera.open();
		Camera.Parameters parameters = camera.getParameters();
		parameters.setPreviewSize(screenWidth, screenHeight);
		parameters.setPictureSize(screenWidth, screenHeight);
		camera.setParameters(parameters);

		camera.setDisplayOrientation(90);
		camera.setPreviewDisplay(holder);
		camera.setPreviewCallback(new StreamIt());
		camera.startPreview();
		camera.autoFocus(null);
	}

	private class StreamIt implements Camera.PreviewCallback {

		@Override
		public void onPreviewFrame(byte[] data, Camera camera) {

		}

	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		try {
			cameraInit();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		if (camera != null) {
			camera.stopPreview();
			camera.release();
			camera = null;
		}
	    System.exit(0);
	}

}
